package com.edu.exam.enums;

/**
 * 基础标准类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum FoundationStandardType {
    COURSE("COURSE", "课程评分标准"),
    EXAM("EXAM", "考试评分标准"),
    ASSIGNMENT("ASSIGNMENT", "作业评分标准"),
    PROJECT("PROJECT", "项目评分标准"),
    PRACTICE("PRACTICE", "实践评分标准"),
    THESIS("THESIS", "论文评分标准"),
    COMPREHENSIVE("COMPREHENSIVE", "综合评分标准");

    private final String code;
    private final String description;

    FoundationStandardType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static FoundationStandardType fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (FoundationStandardType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static FoundationStandardType fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (FoundationStandardType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}